﻿using System;

namespace FrameWork.Core.Ioc
{
    public static class IContainerProviderExtensions
    {
        public static T Resolve<T>(this IContainerProvider provider)
        {
            return (T)provider.Resolve(typeof(T));
        }
        public static T Resolve<T>(this IContainerProvider provider, params (Type Type, object Instance)[] parameters)
        {
            return (T)provider.Resolve(typeof(T), parameters);
        }
        public static T Resolve<T>(this IContainerProvider provider, string name, params (Type Type, object Instance)[] parameters)
        {
            return (T)provider.Resolve(typeof(T), name, parameters);
        }
        public static T Resolve<T>(this IContainerProvider provider, string name)
        {
            return (T)provider.Resolve(typeof(T), name);
        }
        public static bool IsRegistered<T>(this IContainerProvider containerProvider)
        {
            return containerProvider.IsRegistered(typeof(T));
        }
        internal static bool IsRegistered(this IContainerProvider containerProvider, Type type)
        {
            if (containerProvider is IContainerRegistry containerRegistry)
                return containerRegistry.IsRegistered(type);
            return false;
        }
        public static bool IsRegistered<T>(this IContainerProvider containerProvider, string name)
        {
            return containerProvider.IsRegistered(typeof(T), name);
        }

        internal static bool IsRegistered(this IContainerProvider containerProvider, Type type, string name)
        {
            if (containerProvider is IContainerRegistry containerRegistry)
                return containerRegistry.IsRegistered(type, name);
            return false;
        }
    }
}
